ESTI019 - Codificação de Sinais Multimídia - Lab9 - MIDI e IR
Prof. Mário Minami
Alunos:
Neste laboratório, foram utilizadas as bibliotecas Magenta e Librosa, dentro do ambiente de desenvolvimento do Google Colab, para estudar técnicas processamento de áudio MIDI e explorar aspectos relativos à Reposta sonora ao impulso unitário.
Dentre as atividades de processamento desenvolvidas, foi possível atingir os seguintes objetivos:
Objetivos
Link para o ambiente Colab utilizado no desenvolvimento desta prática:
Instalando a biblioteca para manipulação de Áudio MIDI Magenta
##@test {"output": "ignore"}
print('Installing dependencies...')
!apt-get update -qq && apt-get install -qq libfluidsynth1 fluid-soundfont-gm build-essential libasound2-dev libjack-dev
!pip install -qU pyfluidsynth pretty_midi
!pip install -qU magenta
# Hack to allow python to pick up the newly-installed fluidsynth lib.
# This is only needed for the hosted Colab environment.
import ctypes.util
orig_ctypes_util_find_library = ctypes.util.find_library
def proxy_find_library(lib):
if lib == 'fluidsynth':
return 'libfluidsynth.so.1'
else:
return orig_ctypes_util_find_library(lib)
ctypes.util.find_library = proxy_find_library
Importando todas as Bibliotecas utilzadas durante esta prática de laboratório:
from google.colab import files
import magenta
import note_seq
from note_seq.protobuf import music_pb2
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import librosa
import librosa.display
import IPython.display
import random
Everything in Magenta is centered around NoteSequences. This is an abstract representation of a series of notes, each with different pitches, instruments and strike velocities, much like MIDI.
For example, this is a NoteSequence that represents "Twinkle Twinkle Little Star".
twinkle_twinkle = music_pb2.NoteSequence()
# Add the notes to the sequence.
twinkle_twinkle.notes.add(pitch=60, start_time=0.0, end_time=0.5, velocity=80)
twinkle_twinkle.notes.add(pitch=60, start_time=0.5, end_time=1.0, velocity=80)
twinkle_twinkle.notes.add(pitch=67, start_time=1.0, end_time=1.5, velocity=80)
twinkle_twinkle.notes.add(pitch=67, start_time=1.5, end_time=2.0, velocity=80)
twinkle_twinkle.notes.add(pitch=69, start_time=2.0, end_time=2.5, velocity=80)
twinkle_twinkle.notes.add(pitch=69, start_time=2.5, end_time=3.0, velocity=80)
twinkle_twinkle.notes.add(pitch=67, start_time=3.0, end_time=4.0, velocity=80)
twinkle_twinkle.notes.add(pitch=65, start_time=4.0, end_time=4.5, velocity=80)
twinkle_twinkle.notes.add(pitch=65, start_time=4.5, end_time=5.0, velocity=80)
twinkle_twinkle.notes.add(pitch=64, start_time=5.0, end_time=5.5, velocity=80)
twinkle_twinkle.notes.add(pitch=64, start_time=5.5, end_time=6.0, velocity=80)
twinkle_twinkle.notes.add(pitch=62, start_time=6.0, end_time=6.5, velocity=80)
twinkle_twinkle.notes.add(pitch=62, start_time=6.5, end_time=7.0, velocity=80)
twinkle_twinkle.notes.add(pitch=60, start_time=7.0, end_time=8.0, velocity=80)
twinkle_twinkle.total_time = 8
twinkle_twinkle.tempos.add(qpm=60);
# This is a colab utility method that visualizes a NoteSequence.
note_seq.plot_sequence(twinkle_twinkle)
# This is a colab utility method that plays a NoteSequence.
note_seq.play_sequence(twinkle_twinkle,synth=note_seq.fluidsynth)
Pode variar os tempos e as notas
# Asa Branca
asa_branca_piano = music_pb2.NoteSequence()
# CifraClub
asa_branca_piano.notes.add(pitch=72, start_time=0.0, end_time=0.5, velocity=80)
asa_branca_piano.notes.add(pitch=74, start_time=0.5, end_time=1.0, velocity=80)
asa_branca_piano.notes.add(pitch=76, start_time=1.0, end_time=1.5, velocity=80)
asa_branca_piano.notes.add(pitch=79, start_time=1.5, end_time=2.0, velocity=80)
asa_branca_piano.notes.add(pitch=79, start_time=2.0, end_time=2.5, velocity=80)
asa_branca_piano.notes.add(pitch=76, start_time=2.5, end_time=3.0, velocity=80)
asa_branca_piano.notes.add(pitch=77, start_time=3.0, end_time=4.0, velocity=80)
asa_branca_piano.notes.add(pitch=77, start_time=4.0, end_time=4.5, velocity=80)
asa_branca_piano.notes.add(pitch=72, start_time=4.5, end_time=5.0, velocity=80)
asa_branca_piano.notes.add(pitch=74, start_time=5.0, end_time=5.5, velocity=80)
asa_branca_piano.notes.add(pitch=76, start_time=5.5, end_time=6.0, velocity=80)
asa_branca_piano.notes.add(pitch=79, start_time=6.0, end_time=6.5, velocity=80)
asa_branca_piano.notes.add(pitch=79, start_time=6.5, end_time=7.0, velocity=80)
asa_branca_piano.notes.add(pitch=77, start_time=7.0, end_time=8.0, velocity=80)
asa_branca_piano.notes.add(pitch=76, start_time=8.0, end_time=8.5, velocity=80)
asa_branca_piano.notes.add(pitch=72, start_time=8.5, end_time=9.0, velocity=80)
asa_branca_piano.notes.add(pitch=72, start_time=9.0, end_time=9.5, velocity=80)
asa_branca_piano.notes.add(pitch=74, start_time=9.5, end_time=10.0, velocity=80)
asa_branca_piano.notes.add(pitch=76, start_time=10.0, end_time=10.5, velocity=80)
asa_branca_piano.notes.add(pitch=79, start_time=10.5, end_time=11.0, velocity=80)
asa_branca_piano.notes.add(pitch=79, start_time=11.0, end_time=11.5, velocity=80)
asa_branca_piano.notes.add(pitch=77, start_time=11.5, end_time=12.0, velocity=80)
asa_branca_piano.notes.add(pitch=76, start_time=12.0, end_time=12.5, velocity=80)
asa_branca_piano.notes.add(pitch=72, start_time=12.5, end_time=13.0, velocity=80)
asa_branca_piano.notes.add(pitch=77, start_time=13.0, end_time=13.5, velocity=80)
asa_branca_piano.notes.add(pitch=77, start_time=13.5, end_time=14.0, velocity=80)
asa_branca_piano.notes.add(pitch=76, start_time=14.0, end_time=14.5, velocity=80)
asa_branca_piano.notes.add(pitch=74, start_time=14.5, end_time=15.0, velocity=80)
asa_branca_piano.notes.add(pitch=74, start_time=15.0, end_time=16.0, velocity=80)
asa_branca_piano.notes.add(pitch=76, start_time=16.0, end_time=17.5, velocity=80)
asa_branca_piano.notes.add(pitch=74, start_time=17.5, end_time=18.0, velocity=80)
asa_branca_piano.notes.add(pitch=74, start_time=18.0, end_time=19.0, velocity=80)
asa_branca_piano.notes.add(pitch=72, start_time=19.0, end_time=19.5, velocity=80)
asa_branca_piano.notes.add(pitch=72, start_time=19.5, end_time=20.0, velocity=80)
asa_branca_piano.total_time = 20.0
asa_branca_piano.tempos.add(qpm=90);
# This is a colab utility method that visualizes a NoteSequence.
note_seq.plot_sequence(asa_branca_piano)
# This is a colab utility method that plays a NoteSequence.
note_seq.play_sequence(asa_branca_piano,synth=note_seq.fluidsynth)
Pode usar outro instrumento. Por exemplo, uma bateria
drums = music_pb2.NoteSequence()
drums.notes.add(pitch=36, start_time=0, end_time=0.125, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=38, start_time=0, end_time=0.125, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=42, start_time=0, end_time=0.125, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=46, start_time=0, end_time=0.125, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=42, start_time=0.25, end_time=0.375, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=42, start_time=0.375, end_time=0.5, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=42, start_time=0.5, end_time=0.625, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=50, start_time=0.5, end_time=0.625, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=36, start_time=0.75, end_time=0.875, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=38, start_time=0.75, end_time=0.875, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=42, start_time=0.75, end_time=0.875, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=45, start_time=0.75, end_time=0.875, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=36, start_time=1, end_time=1.125, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=42, start_time=1, end_time=1.125, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=46, start_time=1, end_time=1.125, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=42, start_time=1.25, end_time=1.375, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=48, start_time=1.25, end_time=1.375, is_drum=True, instrument=10, velocity=80)
drums.notes.add(pitch=50, start_time=1.25, end_time=1.375, is_drum=True, instrument=10, velocity=80)
drums.total_time = 1.375
drums.tempos.add(qpm=60)
# This is a colab utility method that visualizes a NoteSequence.
note_seq.plot_sequence(drums)
# This is a colab utility method that plays a NoteSequence.
note_seq.play_sequence(drums,synth=note_seq.fluidsynth)
NoteSequence -> MIDI¶When you called the "play_sequence" method above, this converted the NoteSequence to MIDI, and created an HTML widget to play it. This method is specially made for colab notebooks, so it won't work inside your Python script. That method uses the Magenta built-in conversion methods, which you can use in your python script:
# This creates a file called `asa_branca_sample_output.mid`, containing the drums solo we've been using.
note_seq.sequence_proto_to_midi_file(asa_branca_piano, 'asa_branca_sample_output.mid')
# This is a colab utility method to download that file. In your Python script, you
# This creates a file called `drums_sample_output.mid`, containing the drums solo we've been using.
note_seq.sequence_proto_to_midi_file(drums, 'drums_sample_output.mid')
# This is a colab utility method to download that file. In your Python script, you
Adquirindo os arquivos do repositório do GitHub
!wget -q chpn_op7_1_format0.mid https://raw.githubusercontent.com/gabrielsouza-oss/CSM/main/labs/chpn_op7_1_format0.mid
Carregando MIDI
midi_file = note_seq.midi_file_to_note_sequence('chpn_op7_1_format0.mid')
# Handle sustain pedal in midi_file
midi_file = note_seq.apply_sustain_control_changes(midi_file)
note_seq.play_sequence(
midi_file,
synth=note_seq.fluidsynth, sample_rate=22050)
note_seq.plot_sequence(midi_file)
Adquirindo os arquivos do repositório do GitHub
!wget -q https://raw.githubusercontent.com/gabrielsouza-oss/CSM/main/labs/stalbans_omni.wav
!wget -q https://raw.githubusercontent.com/gabrielsouza-oss/CSM/main/labs/Mazurca_Chopin_opus7_no1_with_pedal.wav
!wget -q https://raw.githubusercontent.com/gabrielsouza-oss/CSM/main/labs/usina_main_s1_p5.wav
!wget -q https://raw.githubusercontent.com/gabrielsouza-oss/CSM/main/labs/stairwell_ortf.wav
# Resposta Impulsiva de uma capela de Igreja
ir_chapel, sr_chapel = librosa.load('stalbans_omni.wav', mono = True, sr = 96000)
# Normalização da IR
ir_chapel = librosa.util.normalize(ir_chapel)
IPython.display.Audio(ir_chapel, rate = sr_chapel)
plt.figure()
fig, ax = plt.subplots(figsize=(15, 5))
librosa.display.waveplot(ir_chapel, sr=sr_chapel)
plt.title('IR de uma capela')
Text(0.5, 1.0, 'IR de uma capela')
<Figure size 432x288 with 0 Axes>
"Tocando" Chopin na Capela
Mazurca, sr_Mazurca = librosa.load('Mazurca_Chopin_opus7_no1_with_pedal.wav', mono = True, sr = 22050)
Mazurca = librosa.util.normalize(Mazurca)
reproducao_Chopin_chapel = np.convolve(Mazurca, ir_chapel, mode = 'full')
IPython.display.Audio(reproducao_Chopin_chapel, rate = sr_Mazurca)
# "Tocando" numa Sala de Concertos
ir_hall, sr_hall = librosa.load('usina_main_s1_p5.wav', mono = True, sr = 48000)
ir_hall = librosa.util.normalize(ir_hall)
plt.figure()
fig, ax = plt.subplots(figsize=(15, 5))
librosa.display.waveplot(ir_hall, sr=sr_hall)
plt.title('IR de uma Sala de Concertos')
Text(0.5, 1.0, 'IR de uma Sala de Concertos')
<Figure size 432x288 with 0 Axes>
IPython.display.Audio(ir_hall, rate = sr_hall)
reproducao_Chopin_hall = np.convolve(Mazurca, ir_hall, mode = 'full')
IPython.display.Audio(reproducao_Chopin_hall, rate = sr_Mazurca)
Nesta parte do laboratório, foi desenvolvida a Função generat_music(), utilizada para gerar as músicas de 18s entorno de um determinado pitch escolhido por cada um dos integrantes.
def generat_music(notas,pitch,tempo):
music = music_pb2.NoteSequence()
cont = 0
for i in range(0,notas):
escolha = random.randint(pitch-10,pitch+10)
music.notes.add(pitch=escolha, start_time=cont, end_time=cont+0.5, velocity=80)
print("music.notes.add(pitch="+str(escolha)+" start_time="+str(cont)+", end_time="+str(cont+0.5)+", velocity=80)")
cont += 0.5
music.total_time = (cont+0.5)*notas
music.tempos.add(qpm=tempo)
return music
musica_gab = generat_music(notas=36,pitch=95,tempo=60)
# This is a colab utility method that visualizes a NoteSequence.
note_seq.plot_sequence(musica_gab)
# This is a colab utility method that plays a NoteSequence.
note_seq.play_sequence(musica_gab,synth=note_seq.fluidsynth)
# This creates a file, containing the music we've been using.
note_seq.sequence_proto_to_midi_file(musica_gab, 'musica_gab.mid')
music.notes.add(pitch=88 start_time=0, end_time=0.5, velocity=80) music.notes.add(pitch=101 start_time=0.5, end_time=1.0, velocity=80) music.notes.add(pitch=93 start_time=1.0, end_time=1.5, velocity=80) music.notes.add(pitch=104 start_time=1.5, end_time=2.0, velocity=80) music.notes.add(pitch=93 start_time=2.0, end_time=2.5, velocity=80) music.notes.add(pitch=86 start_time=2.5, end_time=3.0, velocity=80) music.notes.add(pitch=101 start_time=3.0, end_time=3.5, velocity=80) music.notes.add(pitch=96 start_time=3.5, end_time=4.0, velocity=80) music.notes.add(pitch=104 start_time=4.0, end_time=4.5, velocity=80) music.notes.add(pitch=97 start_time=4.5, end_time=5.0, velocity=80) music.notes.add(pitch=85 start_time=5.0, end_time=5.5, velocity=80) music.notes.add(pitch=92 start_time=5.5, end_time=6.0, velocity=80) music.notes.add(pitch=96 start_time=6.0, end_time=6.5, velocity=80) music.notes.add(pitch=89 start_time=6.5, end_time=7.0, velocity=80) music.notes.add(pitch=99 start_time=7.0, end_time=7.5, velocity=80) music.notes.add(pitch=97 start_time=7.5, end_time=8.0, velocity=80) music.notes.add(pitch=97 start_time=8.0, end_time=8.5, velocity=80) music.notes.add(pitch=86 start_time=8.5, end_time=9.0, velocity=80) music.notes.add(pitch=104 start_time=9.0, end_time=9.5, velocity=80) music.notes.add(pitch=102 start_time=9.5, end_time=10.0, velocity=80) music.notes.add(pitch=90 start_time=10.0, end_time=10.5, velocity=80) music.notes.add(pitch=94 start_time=10.5, end_time=11.0, velocity=80) music.notes.add(pitch=85 start_time=11.0, end_time=11.5, velocity=80) music.notes.add(pitch=86 start_time=11.5, end_time=12.0, velocity=80) music.notes.add(pitch=89 start_time=12.0, end_time=12.5, velocity=80) music.notes.add(pitch=89 start_time=12.5, end_time=13.0, velocity=80) music.notes.add(pitch=98 start_time=13.0, end_time=13.5, velocity=80) music.notes.add(pitch=90 start_time=13.5, end_time=14.0, velocity=80) music.notes.add(pitch=91 start_time=14.0, end_time=14.5, velocity=80) music.notes.add(pitch=105 start_time=14.5, end_time=15.0, velocity=80) music.notes.add(pitch=94 start_time=15.0, end_time=15.5, velocity=80) music.notes.add(pitch=93 start_time=15.5, end_time=16.0, velocity=80) music.notes.add(pitch=105 start_time=16.0, end_time=16.5, velocity=80) music.notes.add(pitch=104 start_time=16.5, end_time=17.0, velocity=80) music.notes.add(pitch=88 start_time=17.0, end_time=17.5, velocity=80) music.notes.add(pitch=94 start_time=17.5, end_time=18.0, velocity=80)
musica_victor = generat_music(notas=36,pitch=20,tempo=120)
# This is a colab utility method that visualizes a NoteSequence.
note_seq.plot_sequence(musica_victor)
# This is a colab utility method that plays a NoteSequence.
note_seq.play_sequence(musica_victor,synth=note_seq.fluidsynth)
# This creates a file, containing the music we've been using.
note_seq.sequence_proto_to_midi_file(musica_victor, 'musica_victor.mid')
music.notes.add(pitch=23 start_time=0, end_time=0.5, velocity=80) music.notes.add(pitch=11 start_time=0.5, end_time=1.0, velocity=80) music.notes.add(pitch=17 start_time=1.0, end_time=1.5, velocity=80) music.notes.add(pitch=15 start_time=1.5, end_time=2.0, velocity=80) music.notes.add(pitch=22 start_time=2.0, end_time=2.5, velocity=80) music.notes.add(pitch=20 start_time=2.5, end_time=3.0, velocity=80) music.notes.add(pitch=23 start_time=3.0, end_time=3.5, velocity=80) music.notes.add(pitch=10 start_time=3.5, end_time=4.0, velocity=80) music.notes.add(pitch=13 start_time=4.0, end_time=4.5, velocity=80) music.notes.add(pitch=10 start_time=4.5, end_time=5.0, velocity=80) music.notes.add(pitch=14 start_time=5.0, end_time=5.5, velocity=80) music.notes.add(pitch=30 start_time=5.5, end_time=6.0, velocity=80) music.notes.add(pitch=20 start_time=6.0, end_time=6.5, velocity=80) music.notes.add(pitch=28 start_time=6.5, end_time=7.0, velocity=80) music.notes.add(pitch=24 start_time=7.0, end_time=7.5, velocity=80) music.notes.add(pitch=19 start_time=7.5, end_time=8.0, velocity=80) music.notes.add(pitch=13 start_time=8.0, end_time=8.5, velocity=80) music.notes.add(pitch=18 start_time=8.5, end_time=9.0, velocity=80) music.notes.add(pitch=21 start_time=9.0, end_time=9.5, velocity=80) music.notes.add(pitch=29 start_time=9.5, end_time=10.0, velocity=80) music.notes.add(pitch=18 start_time=10.0, end_time=10.5, velocity=80) music.notes.add(pitch=24 start_time=10.5, end_time=11.0, velocity=80) music.notes.add(pitch=23 start_time=11.0, end_time=11.5, velocity=80) music.notes.add(pitch=28 start_time=11.5, end_time=12.0, velocity=80) music.notes.add(pitch=16 start_time=12.0, end_time=12.5, velocity=80) music.notes.add(pitch=19 start_time=12.5, end_time=13.0, velocity=80) music.notes.add(pitch=12 start_time=13.0, end_time=13.5, velocity=80) music.notes.add(pitch=22 start_time=13.5, end_time=14.0, velocity=80) music.notes.add(pitch=15 start_time=14.0, end_time=14.5, velocity=80) music.notes.add(pitch=20 start_time=14.5, end_time=15.0, velocity=80) music.notes.add(pitch=25 start_time=15.0, end_time=15.5, velocity=80) music.notes.add(pitch=11 start_time=15.5, end_time=16.0, velocity=80) music.notes.add(pitch=17 start_time=16.0, end_time=16.5, velocity=80) music.notes.add(pitch=18 start_time=16.5, end_time=17.0, velocity=80) music.notes.add(pitch=24 start_time=17.0, end_time=17.5, velocity=80) music.notes.add(pitch=15 start_time=17.5, end_time=18.0, velocity=80)
musica_joao = generat_music(notas=36,pitch=50,tempo=90)
# This is a colab utility method that visualizes a NoteSequence.
note_seq.plot_sequence(musica_joao)
# This is a colab utility method that plays a NoteSequence.
note_seq.play_sequence(musica_joao,synth=note_seq.fluidsynth)
# This creates a file, containing the music we've been using.
note_seq.sequence_proto_to_midi_file(musica_joao, 'musica_joao.mid')
music.notes.add(pitch=55 start_time=0, end_time=0.5, velocity=80) music.notes.add(pitch=40 start_time=0.5, end_time=1.0, velocity=80) music.notes.add(pitch=44 start_time=1.0, end_time=1.5, velocity=80) music.notes.add(pitch=55 start_time=1.5, end_time=2.0, velocity=80) music.notes.add(pitch=40 start_time=2.0, end_time=2.5, velocity=80) music.notes.add(pitch=44 start_time=2.5, end_time=3.0, velocity=80) music.notes.add(pitch=55 start_time=3.0, end_time=3.5, velocity=80) music.notes.add(pitch=43 start_time=3.5, end_time=4.0, velocity=80) music.notes.add(pitch=55 start_time=4.0, end_time=4.5, velocity=80) music.notes.add(pitch=47 start_time=4.5, end_time=5.0, velocity=80) music.notes.add(pitch=47 start_time=5.0, end_time=5.5, velocity=80) music.notes.add(pitch=46 start_time=5.5, end_time=6.0, velocity=80) music.notes.add(pitch=59 start_time=6.0, end_time=6.5, velocity=80) music.notes.add(pitch=45 start_time=6.5, end_time=7.0, velocity=80) music.notes.add(pitch=56 start_time=7.0, end_time=7.5, velocity=80) music.notes.add(pitch=44 start_time=7.5, end_time=8.0, velocity=80) music.notes.add(pitch=43 start_time=8.0, end_time=8.5, velocity=80) music.notes.add(pitch=43 start_time=8.5, end_time=9.0, velocity=80) music.notes.add(pitch=43 start_time=9.0, end_time=9.5, velocity=80) music.notes.add(pitch=57 start_time=9.5, end_time=10.0, velocity=80) music.notes.add(pitch=41 start_time=10.0, end_time=10.5, velocity=80) music.notes.add(pitch=47 start_time=10.5, end_time=11.0, velocity=80) music.notes.add(pitch=54 start_time=11.0, end_time=11.5, velocity=80) music.notes.add(pitch=44 start_time=11.5, end_time=12.0, velocity=80) music.notes.add(pitch=40 start_time=12.0, end_time=12.5, velocity=80) music.notes.add(pitch=40 start_time=12.5, end_time=13.0, velocity=80) music.notes.add(pitch=59 start_time=13.0, end_time=13.5, velocity=80) music.notes.add(pitch=57 start_time=13.5, end_time=14.0, velocity=80) music.notes.add(pitch=45 start_time=14.0, end_time=14.5, velocity=80) music.notes.add(pitch=46 start_time=14.5, end_time=15.0, velocity=80) music.notes.add(pitch=41 start_time=15.0, end_time=15.5, velocity=80) music.notes.add(pitch=50 start_time=15.5, end_time=16.0, velocity=80) music.notes.add(pitch=42 start_time=16.0, end_time=16.5, velocity=80) music.notes.add(pitch=43 start_time=16.5, end_time=17.0, velocity=80) music.notes.add(pitch=49 start_time=17.0, end_time=17.5, velocity=80) music.notes.add(pitch=40 start_time=17.5, end_time=18.0, velocity=80)
Nesta parte do laboratório, foi desenvolvida a Função reproduz_ambiente() para realizar a operação de convolução entre a reposta impulsiva de cada ambiente devidamente normalizada e o aúdio musical escolhido, também devidamente normalizado.
def reproduz_ambiente(arquivo_impulso,arquivo_musica):
# Resposta Impulsiva
ir_chapel, sr_chapel = librosa.load(arquivo_impulso, mono = True)
# Normalização da IR
ir_chapel = librosa.util.normalize(ir_chapel)
#Leitura da musica
Mazurca, sr_Mazurca = librosa.load(arquivo_musica, mono = True)
#Normalizando a musica
Mazurca = librosa.util.normalize(Mazurca)
#reproduzindo no ambiente
reproducao = np.convolve(Mazurca, ir_chapel, mode = 'full')
#Plotando a Musica
display(IPython.display.Audio(reproducao, rate = sr_Mazurca))
Gerando a música mais longa a ser utilizada nos diversos ambientes
musica_longa = generat_music(notas=70,pitch=25,tempo=60)
# This is a colab utility method that visualizes a NoteSequence.
note_seq.plot_sequence(musica_longa)
# This is a colab utility method that plays a NoteSequence.
note_seq.play_sequence(musica_longa,synth=note_seq.fluidsynth)
# This creates a file, containing the music we've been using.
note_seq.sequence_proto_to_midi_file(musica_longa, 'musica_longa.mid')
music.notes.add(pitch=25 start_time=0, end_time=0.5, velocity=80) music.notes.add(pitch=26 start_time=0.5, end_time=1.0, velocity=80) music.notes.add(pitch=22 start_time=1.0, end_time=1.5, velocity=80) music.notes.add(pitch=20 start_time=1.5, end_time=2.0, velocity=80) music.notes.add(pitch=26 start_time=2.0, end_time=2.5, velocity=80) music.notes.add(pitch=24 start_time=2.5, end_time=3.0, velocity=80) music.notes.add(pitch=15 start_time=3.0, end_time=3.5, velocity=80) music.notes.add(pitch=27 start_time=3.5, end_time=4.0, velocity=80) music.notes.add(pitch=30 start_time=4.0, end_time=4.5, velocity=80) music.notes.add(pitch=17 start_time=4.5, end_time=5.0, velocity=80) music.notes.add(pitch=23 start_time=5.0, end_time=5.5, velocity=80) music.notes.add(pitch=23 start_time=5.5, end_time=6.0, velocity=80) music.notes.add(pitch=35 start_time=6.0, end_time=6.5, velocity=80) music.notes.add(pitch=19 start_time=6.5, end_time=7.0, velocity=80) music.notes.add(pitch=23 start_time=7.0, end_time=7.5, velocity=80) music.notes.add(pitch=29 start_time=7.5, end_time=8.0, velocity=80) music.notes.add(pitch=18 start_time=8.0, end_time=8.5, velocity=80) music.notes.add(pitch=23 start_time=8.5, end_time=9.0, velocity=80) music.notes.add(pitch=17 start_time=9.0, end_time=9.5, velocity=80) music.notes.add(pitch=18 start_time=9.5, end_time=10.0, velocity=80) music.notes.add(pitch=28 start_time=10.0, end_time=10.5, velocity=80) music.notes.add(pitch=30 start_time=10.5, end_time=11.0, velocity=80) music.notes.add(pitch=25 start_time=11.0, end_time=11.5, velocity=80) music.notes.add(pitch=35 start_time=11.5, end_time=12.0, velocity=80) music.notes.add(pitch=26 start_time=12.0, end_time=12.5, velocity=80) music.notes.add(pitch=19 start_time=12.5, end_time=13.0, velocity=80) music.notes.add(pitch=21 start_time=13.0, end_time=13.5, velocity=80) music.notes.add(pitch=24 start_time=13.5, end_time=14.0, velocity=80) music.notes.add(pitch=18 start_time=14.0, end_time=14.5, velocity=80) music.notes.add(pitch=28 start_time=14.5, end_time=15.0, velocity=80) music.notes.add(pitch=22 start_time=15.0, end_time=15.5, velocity=80) music.notes.add(pitch=23 start_time=15.5, end_time=16.0, velocity=80) music.notes.add(pitch=16 start_time=16.0, end_time=16.5, velocity=80) music.notes.add(pitch=15 start_time=16.5, end_time=17.0, velocity=80) music.notes.add(pitch=30 start_time=17.0, end_time=17.5, velocity=80) music.notes.add(pitch=23 start_time=17.5, end_time=18.0, velocity=80) music.notes.add(pitch=29 start_time=18.0, end_time=18.5, velocity=80) music.notes.add(pitch=28 start_time=18.5, end_time=19.0, velocity=80) music.notes.add(pitch=20 start_time=19.0, end_time=19.5, velocity=80) music.notes.add(pitch=26 start_time=19.5, end_time=20.0, velocity=80) music.notes.add(pitch=32 start_time=20.0, end_time=20.5, velocity=80) music.notes.add(pitch=29 start_time=20.5, end_time=21.0, velocity=80) music.notes.add(pitch=15 start_time=21.0, end_time=21.5, velocity=80) music.notes.add(pitch=21 start_time=21.5, end_time=22.0, velocity=80) music.notes.add(pitch=30 start_time=22.0, end_time=22.5, velocity=80) music.notes.add(pitch=25 start_time=22.5, end_time=23.0, velocity=80) music.notes.add(pitch=23 start_time=23.0, end_time=23.5, velocity=80) music.notes.add(pitch=15 start_time=23.5, end_time=24.0, velocity=80) music.notes.add(pitch=29 start_time=24.0, end_time=24.5, velocity=80) music.notes.add(pitch=28 start_time=24.5, end_time=25.0, velocity=80) music.notes.add(pitch=15 start_time=25.0, end_time=25.5, velocity=80) music.notes.add(pitch=19 start_time=25.5, end_time=26.0, velocity=80) music.notes.add(pitch=35 start_time=26.0, end_time=26.5, velocity=80) music.notes.add(pitch=33 start_time=26.5, end_time=27.0, velocity=80) music.notes.add(pitch=18 start_time=27.0, end_time=27.5, velocity=80) music.notes.add(pitch=32 start_time=27.5, end_time=28.0, velocity=80) music.notes.add(pitch=21 start_time=28.0, end_time=28.5, velocity=80) music.notes.add(pitch=31 start_time=28.5, end_time=29.0, velocity=80) music.notes.add(pitch=25 start_time=29.0, end_time=29.5, velocity=80) music.notes.add(pitch=27 start_time=29.5, end_time=30.0, velocity=80) music.notes.add(pitch=29 start_time=30.0, end_time=30.5, velocity=80) music.notes.add(pitch=34 start_time=30.5, end_time=31.0, velocity=80) music.notes.add(pitch=34 start_time=31.0, end_time=31.5, velocity=80) music.notes.add(pitch=15 start_time=31.5, end_time=32.0, velocity=80) music.notes.add(pitch=30 start_time=32.0, end_time=32.5, velocity=80) music.notes.add(pitch=17 start_time=32.5, end_time=33.0, velocity=80) music.notes.add(pitch=33 start_time=33.0, end_time=33.5, velocity=80) music.notes.add(pitch=21 start_time=33.5, end_time=34.0, velocity=80) music.notes.add(pitch=16 start_time=34.0, end_time=34.5, velocity=80) music.notes.add(pitch=27 start_time=34.5, end_time=35.0, velocity=80)
!wget -q https://raw.githubusercontent.com/gabrielsouza-oss/CSM/main/labs/musica_longa.wav
# Resposta Impulsiva de uma capela de Igreja
reproduz_ambiente('musica_longa.wav','stalbans_omni.wav')
# "Tocando" numa Sala de Concertos
reproduz_ambiente('musica_longa.wav','usina_main_s1_p5.wav')
# "Tocando" numa Escada de Universidade
reproduz_ambiente('musica_longa.wav','stairwell_ortf.wav')
Nesta parte do laboratório, foi desenvolvida a Função reproduz_ambiente() para realizar a operação de convolução entre a reposta impulsiva de cada ambiente devidamente normalizada e o aúdio musical escolhido, também devidamente normalizado.
Gerando a música mais longa a ser utilizada nos diversos ambientes
!wget -q https://github.com/JohnGarrido/ESTI019/blob/main/lab_8/kisskiss.mp3?raw=true
!mv kisskiss.mp3?raw=true kisskiss.mp3
# Resposta Impulsiva de uma capela de Igreja
reproduz_ambiente('kisskiss.wav','stalbans_omni.wav')
# "Tocando" numa Sala de Concertos
reproduz_ambiente('kisskiss.mp3','usina_main_s1_p5.wav')
/usr/local/lib/python3.7/dist-packages/librosa/core/audio.py:161: UserWarning: PySoundFile failed. Trying audioread instead.
warnings.warn('PySoundFile failed. Trying audioread instead.')
# "Tocando" numa Escada de Universidade
reproduz_ambiente('kisskiss.mp3','stairwell_ortf.wav')
/usr/local/lib/python3.7/dist-packages/librosa/core/audio.py:161: UserWarning: PySoundFile failed. Trying audioread instead.
warnings.warn('PySoundFile failed. Trying audioread instead.')
Neste laboratório, através da manipulação de dados de áudio MIDI, foi possível aplicar técnicas de composição musical e estudo de repostas ao impulso unitário sonoras.
Através das bibliotecas Librosa e Magenta, foi possível realizar processos de criação e manipulação de arquivos de áudio MIDI, alterando sua qualidade, sonoridade e aspectos acústicos de reververação.
A partir dos sinais criados e processados, foram extraídas componentes como:
Leitura , visualização de waveform e análise de composição de tons musicais de áudios MIDI
Reprodução de áudios MIDI em diferentes ambientes simulados, alterando as características acústicas de reverberação e eco nos áudios MIDI, verificando suas peculiaridades
Estudo dos efeitos da operação de convolução com a reposta ao impulso unitário em aúdios